<template>
<div>
   <content_top title="系统信息"></content_top>
   
   <div class="g_box">
		<div class="g_head">
			<h3>系统信息设置</h3>
		</div>
		<div class="g_box_con" style="padding: 30px 50px;width:900px;;">
			<Form ref="form" :model="info" label-position="right" :label-width="150" :rules="ruleValidate">

				<FormItem label="系统名称:" prop="sys_name">
					<Input v-model="info.sys_name" style="width:300px;"></Input>
					<p class="info">站点名称，将显示在登录界面等位置</p>
				</FormItem>
				<FormItem label="默认区时:" prop="zone_time">
					<Select v-model="info.zone_time"  style="width:300px;">
						<Option value="(GMT+08:00)BeiJing,HongKong">(GMT+08:00)BeiJing,HongKong</Option>
					</Select>
					<p class="info">设置系统使用的区时，中国为+8</p>
				</FormItem>
				<FormItem label="系统LOGO:" prop="sys_logo">
					<!--Input v-model="info.sys_logo" style="width:300px;"></Input-->
					<img :src="info.sys_logo" v-if="info.sys_logo!=''" style="display: inline-block;width: 100px;">
					<Upload :action="upload_url" style="display: inline-block;" :show-upload-list="false" :on-success="success">
						<Button icon="ios-cloud-upload-outline">选择上传文件</Button>
					</Upload>
					
					<p class="info">只能上传jpg/png格式文件，文件不能超过50kb</p>
				</FormItem>
				<FormItem label="系统最大提醒金额:">
					<Input v-model="info.max_money" style="width:300px;"></Input>
					<p class="info">设置后会对超过该金额的记账进行弹框提醒</p>
				</FormItem>
				<FormItem label="系统状态:">
					<i-switch v-model="info.sys_status" :true-value="1" :false-value="0" >
						<span slot="open">开</span>
						<span slot="close">关</span>
					</i-switch>
					<p class="info">可暂时将系统关闭，其他人无法访问，但不影响权限组管理员访问</p>
				</FormItem>
				<FormItem label="关闭原因:">
					<Input type="textarea" v-model="info.reason" style="width:300px;"></Input>
					<p class="info">档系统处于关闭状态时，普通用户登录将会无法登录并看到关闭原因</p>
				</FormItem>
				<FormItem>
					<Button type="primary" @click="handleSubmit('form')">提交</Button>
				</FormItem>
			</Form>
		</div>
	</div>
</div>
</template>

<script>
import content_top from '@/themes/components/content_top';
import Wcore from '@/libs/common';
export default {
    name: 'setting',
    data () {
        return {
			info:{
				sys_name:'',
				zone_time:'',
				sys_logo:'',
				max_money:'',
				sys_status:1,
				reason:''
			},
			ruleValidate:{
				sys_name:[
					{ required: true, message: '系统名称不能为空', trigger: 'blur' },
				],
				zone_time:[
					{ required: true, message: '请选择系统时区', trigger: 'blur' },
				],
				sys_logo:[
					{ required: true, message: '请设置系统LOGO', trigger: 'blur' },
				]
			},
			upload_url:Whttp.upload_url
        };
    },
	components:{
		content_top
	},
	created(){
		this.load_data();
	},
    computed: {
       
    },
	methods:{
		load_data(){
			
			var self = this;
			Whttp.load("System/Config/get_info",{},function(result){
				result['sys_status'] = parseInt(result['sys_status']);
				for(var i in result){
					self.info[i] = result[i];
				}
				
				
				
			});
		},
		handleSubmit (name) {
			var self = this;
			this.$refs[name].validate((valid) => {
				if (valid) {
					self.save();
				}
			})
		},
		save(){
			var self = this;
			var postdata = {
				info:this.info
			};
			Whttp.load("System/Config/save",postdata,function(result){
				Wcore.setData('setMaxMoney',self.info.max_money);
				alert('保存成功');
			});

		},
		success(res){
			if(res.result_code==0){
				this.info.sys_logo  = res.data[0].url;
			}
			
		}
	}
};
</script>
<style scoped>
.info{color:#999;}
</style>